package name.matthewgreet.example2.common; import java.util.Collection; /** * A Transformer to transform entities into Value Objects and used by all versions of {@link EntityUtil#transform}. * Implementors map the entity fields to the value fields. * * @param <E> entity * @param <V> value object */ public interface EntityTransformer<E, V> { /** * Returns a Value Object derived from entity. Not called if entity is null. Can return null to skip value from * any Value Object collection. */ V transform(E entity); /** * Notification that {@link #transform} is about to be called for a single entity that's not part of a collection. * entity can be null. */ default void startSingle(E entity) {} /** * Notification that {@link #transform} is about to be called only for multiple entities that are part of a * collection. entities can be null. */ default void startMultiple(Collection<E> entities) {} /** * Notification that calls to {@link #transform} for a single entity that's not part of a collection have completed. * entity can be null. */ default void endSingle(E entity) {} /** * Notification that calls to {@link #transform} for multiple entities that are part of a collection have completed. * entities can be null. */ default void endMultiple(Collection<E> entities) {} }